package edu.luc.cs.gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.KeyStroke;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;
import javax.swing.SwingConstants;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.SwingUtilities;

import edu.luc.cs.backend.CourseSection;
import edu.luc.cs.backend.Employee;
import edu.luc.cs.backend.Student;
import edu.luc.cs.backend.UniversitySystem;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class UnivLogin extends javax.swing.JFrame {
	private UniversitySystem uSys;
	private AbstractAction addStaffAndCloseAction;
	private JButton addStaffButton;
	private JTextField addStaffSexText;
	private JTextField addStaffDOBText;
	private JTextField addStaffLNameText;
	private AbstractAction manageStudentsAction;
	private JTextField addStaffFNameText;
	private JLabel addStaffSexLabel;
	private JLabel addStaffDOBLabel;
	private JLabel addStaffLNameLabel;
	private JLabel addStaffFNameLabel;
	private AbstractAction removeStaffAction;
	private JButton exitButton;
	private JLabel univLabel;
	private JLabel useridLabel;
	private JFrame manageStaffJFrame;
	private JButton manageCoursesButton;
	private JButton manageStudentsButton;
	private JButton manageStaffButton;
	private JFrame adminJFrame;
	private AbstractAction closeLoginAction;
	private JFrame employeeStatsJFrame;
	private AbstractAction addCourseToEmployeeButton;
	private JScrollPane jScrollPane2;
	private JList addCourseToEmployeeList;
	private JButton addCourseToEmployee;
	private JScrollPane jScrollPane1;
	private AbstractAction viewInfoAction;
	private JTextArea employeeInfoText;
	private JList employeeJList;
	private JButton removeEmployeeButton;
	private JButton addEmployeeButton;
	private JButton viewEmployeeButton;
	private AbstractAction loginAction;
	private JFrame UserJFrame;
	private JLabel userTypeLabel;
	private AbstractAction closeAboutAction;
	private JLabel aboutLabel;
	private JButton aboutButton;
	private JDialog jDialog1;
	private AbstractAction aboutAction;
	private JMenuItem jMenuItem1;
	private JMenu jMenu2;
	private JMenu jMenu1;
	private JMenuBar loginMenuBar;
	private JComboBox userTypeCombo;
	private JTextArea userIdTextField;
	private JButton loginButton;
	private AbstractAction manageStaffAction;
	private AbstractAction addStaffAction;
	private DefaultComboBoxModel employeeJListModel;
	private JFrame addStaffJPanel;
	private String manager;
	private AbstractAction manageCoursesAction;
	private String currentEmpInView;
	private String currentCourseInView;
	
	

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				UnivLogin inst = new UnivLogin();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public UnivLogin() {
		super();
		uSys = new UniversitySystem();
		initGUI();
	}
	
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
			getContentPane().setLayout(thisLayout);
			this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			{
				loginMenuBar = new JMenuBar();
				setJMenuBar(loginMenuBar);
				loginMenuBar.setSize(382, 30);
				{
					jMenu1 = new JMenu();
					loginMenuBar.add(jMenu1);
					jMenu1.setText("File");
				}
				{
					jMenu2 = new JMenu();
					loginMenuBar.add(jMenu2);
					jMenu2.setText("Help");
					{
						jMenuItem1 = new JMenuItem();
						jMenu2.add(jMenuItem1);
						jMenuItem1.setText("jMenuItem1");
						jMenuItem1.setAction(getAboutAction());
					}
				}
			}
			{
				exitButton = new JButton();
				exitButton.setText("Exit");
				exitButton.setAction(getCloseLoginAction());
			}
			{
				loginButton = new JButton();
				loginButton.setText("Login");
				loginButton.setAction(getLoginAction());
			}
			{
				univLabel = new JLabel();
				univLabel.setText("University Information System");
				univLabel.setFont(new java.awt.Font("SansSerif",1,18));
			}
			{
				userIdTextField = new JTextArea();
			}
			{
				useridLabel = new JLabel();
				useridLabel.setText("User Id:");
			}
			{
				ComboBoxModel userTypeComboModel = 
					new DefaultComboBoxModel(
							new String[] { "Student", "Employee", "Admin" });
				userTypeCombo = new JComboBox();
				userTypeCombo.setModel(userTypeComboModel);
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap()
				.addComponent(univLabel, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(userIdTextField, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
				        .addGap(8))
				    .addComponent(useridLabel, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getUserTypeLabel(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(userTypeCombo, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
				.addGap(23)
				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(loginButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(exitButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(29, 29));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(35, 35)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				        .addComponent(univLabel, GroupLayout.PREFERRED_SIZE, 321, GroupLayout.PREFERRED_SIZE)
				        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 0, Short.MAX_VALUE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addGap(25)
				        .addGroup(thisLayout.createParallelGroup()
				            .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                .addComponent(useridLabel, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
				                .addGap(18))
				            .addComponent(getUserTypeLabel(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 79, GroupLayout.PREFERRED_SIZE))
				        .addGroup(thisLayout.createParallelGroup()
				            .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                .addComponent(userIdTextField, GroupLayout.PREFERRED_SIZE, 174, GroupLayout.PREFERRED_SIZE)
				                .addGap(0, 48, Short.MAX_VALUE))
				            .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                .addGroup(thisLayout.createParallelGroup()
				                    .addComponent(userTypeCombo, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 155, GroupLayout.PREFERRED_SIZE)
				                    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
				                        .addGap(58)
				                        .addComponent(loginButton, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
				                        .addGap(30)))
				                .addComponent(exitButton, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
				                .addGap(0, 0, Short.MAX_VALUE)))))
				.addContainerGap(21, 21));
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAboutAction() {
		if(aboutAction == null) {
			aboutAction = new AbstractAction("About", null) {
				public void actionPerformed(ActionEvent evt) {
					getJDialog1().pack();
					getJDialog1().setLocationRelativeTo(null);
					getJDialog1().setVisible(true);
				}
			};
		}
		
		return aboutAction;
	}
	
	private JDialog getJDialog1() {
		if(jDialog1 == null) {
			jDialog1 = new JDialog(this);
			GroupLayout jDialog1Layout = new GroupLayout((JComponent)jDialog1.getContentPane());
			jDialog1.getContentPane().setLayout(jDialog1Layout);
			jDialog1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			jDialog1Layout.setHorizontalGroup(jDialog1Layout.createSequentialGroup()
				.addContainerGap(117, 117)
				.addComponent(getAboutLabel(), GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE)
				.addGap(0, 60, Short.MAX_VALUE)
				.addComponent(getAboutButton(), GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
				.addContainerGap());
			jDialog1Layout.setVerticalGroup(jDialog1Layout.createSequentialGroup()
				.addContainerGap(34, 34)
				.addComponent(getAboutLabel(), GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
				.addGap(0, 44, Short.MAX_VALUE)
				.addComponent(getAboutButton(), GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
				.addContainerGap());
		}
		return jDialog1;
	}
	
	private JButton getAboutButton() {
		if(aboutButton == null) {
			aboutButton = new JButton();
			aboutButton.setText("OK");
			aboutButton.setOpaque(false);
			aboutButton.setAction(getCloseAboutAction());
		}
		return aboutButton;
	}
	
	private JLabel getAboutLabel() {
		if(aboutLabel == null) {
			aboutLabel = new JLabel();
			aboutLabel.setText("Christopher Bun");
			aboutLabel.setHorizontalAlignment(SwingConstants.CENTER);
		}
		return aboutLabel;
	}
	
	private AbstractAction getCloseAboutAction() {
		if(closeAboutAction == null) {
			closeAboutAction = new AbstractAction("OK", null) {
				public void actionPerformed(ActionEvent evt) {
					getJDialog1().dispose();
				}
			};
		}
		return closeAboutAction;
	}
	
	private JLabel getUserTypeLabel() {
		if(userTypeLabel == null) {
			userTypeLabel = new JLabel();
			userTypeLabel.setText("User Type:");
		}
		return userTypeLabel;
	}
	
	private JFrame getUserJFrame(String uid) {
		if(UserJFrame == null) {
			UserJFrame = new JFrame();
			UserJFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		}
		return UserJFrame;
	}
	
	private AbstractAction getLoginAction() {
		if(loginAction == null) {
			loginAction = new AbstractAction("Login", null) {
				public void actionPerformed(ActionEvent evt) {
					String uid = userIdTextField.getText();
					String userType = userTypeCombo.getSelectedItem().toString();				
					if (!uid.equals("") && (!uid.equals("Enter a User Id!"))) {
						uSys.setCurrentUser(uid);
						if (userType.equals("Student")) {
							JFrame user = getUserJFrame(uid);
							user.pack();
							user.setLocationRelativeTo(null);
							user.setVisible(true);
						}
						else if (userType.equals("Admin")) {
							JFrame admin = getAdminJFrame();
							admin.pack();
							admin.setLocationRelativeTo(null);
							admin.setVisible(true);
						}
					}
					else userIdTextField.setText("Enter a User Id!");
				}
			};
		}
		return loginAction;
	}
	
	private AbstractAction getCloseLoginAction() {
		if(closeLoginAction == null) {
			closeLoginAction = new AbstractAction("Exit", null) {
				public void actionPerformed(ActionEvent evt) {
					System.exit(DISPOSE_ON_CLOSE);
				}
			};
		}
		return closeLoginAction;
	}
	
	private JFrame getAdminJFrame() {
		if(adminJFrame == null) {
			adminJFrame = new JFrame();
			BoxLayout adminJFrameLayout = new BoxLayout(adminJFrame.getContentPane(), javax.swing.BoxLayout.X_AXIS);
			adminJFrame.getContentPane().setLayout(adminJFrameLayout);
			adminJFrame.setTitle("Administration");
			adminJFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			adminJFrame.getContentPane().add(getManageStaffButton());
			adminJFrame.getContentPane().add(getManageStudentsButton());
			adminJFrame.getContentPane().add(getManageCoursesButton());
		}
		return adminJFrame;
	}
	
	private JButton getManageStaffButton() {
		if(manageStaffButton == null) {
			manageStaffButton = new JButton();
			BoxLayout viewStaffButtonLayout = new BoxLayout(manageStaffButton, javax.swing.BoxLayout.X_AXIS);
			manageStaffButton.setLayout(viewStaffButtonLayout);
			manageStaffButton.setText("Manage Staff");
			manageStaffButton.setAction(getManageStaffAction());
		}
		return manageStaffButton;
	}
	
	private JButton getManageStudentsButton() {
		if(manageStudentsButton == null) {
			manageStudentsButton = new JButton();
			BoxLayout jButton1Layout = new BoxLayout(manageStudentsButton, javax.swing.BoxLayout.X_AXIS);
			manageStudentsButton.setText("Manage Students");
			//manageStudentsButton.setLayout(null);
			manageStudentsButton.setAction(getManageStudentsAction());
		}
		return manageStudentsButton;
	}
	
	private JButton getManageCoursesButton() {
		if(manageCoursesButton == null) {
			manageCoursesButton = new JButton();
			manageCoursesButton.setText("Manage Courses");
			manageCoursesButton.setLayout(null);
			manageCoursesButton.setAction(getManageCoursesAction());
		}
		return manageCoursesButton;
	}
	
	private JFrame getManageStaffJFrame() {
		if(manageStaffJFrame == null) {
			manageStaffJFrame = new JFrame();
			GroupLayout manageStaffJFrameLayout = new GroupLayout((JComponent)manageStaffJFrame.getContentPane());
			manageStaffJFrame.getContentPane().setLayout(manageStaffJFrameLayout);
			manageStaffJFrame.setTitle("Manager");
			manageStaffJFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			manageStaffJFrameLayout.setHorizontalGroup(manageStaffJFrameLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(manageStaffJFrameLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, manageStaffJFrameLayout.createSequentialGroup()
				        .addComponent(getViewEmployeeButton(), GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
				        .addGap(44)
				        .addComponent(getAddEmployeeButton(), GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 52, Short.MAX_VALUE)
				        .addComponent(getRemoveEmployeeButton(), GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE))
				    .addComponent(getEmployeeJList(), GroupLayout.Alignment.LEADING, 0, 297, Short.MAX_VALUE))
				.addContainerGap());
			manageStaffJFrameLayout.setVerticalGroup(manageStaffJFrameLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(manageStaffJFrameLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getViewEmployeeButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddEmployeeButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getRemoveEmployeeButton(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
				.addGap(17)
				.addComponent(getEmployeeJList(), GroupLayout.PREFERRED_SIZE, 332, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(26, Short.MAX_VALUE));
		}
		return manageStaffJFrame;
	}
	
	private JButton getViewEmployeeButton() {
		if(viewEmployeeButton == null) {
			viewEmployeeButton = new JButton();
			viewEmployeeButton.setText("View");
			viewEmployeeButton.setAction(getViewInfoAction());
		}
		return viewEmployeeButton;
	}
	
	private JButton getAddEmployeeButton() {
		if(addEmployeeButton == null) {
			addEmployeeButton = new JButton();
			addEmployeeButton.setText("Add");
			addEmployeeButton.setAction(getAddStaffAction());
		}
		return addEmployeeButton;
	}
	
	private JButton getRemoveEmployeeButton() {
		if(removeEmployeeButton == null) {
			removeEmployeeButton = new JButton();
			removeEmployeeButton.setText("Remove");
			removeEmployeeButton.setAction(getRemoveStaffAction());
		}
		return removeEmployeeButton;
	}
	
	private JList getEmployeeJList() {
		String[] names;
		// If managing students
		if (manager.equals("Student")) {
			ArrayList<Student> std = uSys.getStudents();
			names = new String[std.size()];
			for (int i = 0; i < std.size(); i++) {
				
				names[i] = std.get(i).getUvid() + ": \t" + std.get(i).getName().toString();
			}
		}
		
		else if (manager.equals("Course")) {
			ArrayList<CourseSection> cs = uSys.getCourseCatalog();
			names = new String[cs.size()];
			for (int i = 0; i < cs.size(); i++) {			
				names[i] = cs.get(i).getCsid() + ": \t" + cs.get(i).getCourseNumber().toString();
			}
		}
		// If managing employees
		else{
			ArrayList<Employee> ppl = uSys.getStaff();
			names = new String[ppl.size()];
			for (int i = 0; i < ppl.size(); i++) {
				names[i] = ppl.get(i).getStaffId() + ": \t" + ppl.get(i).getName().toString();
			}
		}
		if(employeeJList == null) {
			employeeJListModel = 
				new DefaultComboBoxModel(names);
			employeeJList = new JList();
			employeeJList.setModel(employeeJListModel);
		}
		else {
			employeeJListModel = 
				new DefaultComboBoxModel(names);
			employeeJList.setModel(employeeJListModel);
		}
		return employeeJList;
	}
	
	private AbstractAction getManageStaffAction() {
		if(manageStaffAction == null) {
		manageStaffAction = new AbstractAction("Manage Staff", null) {
				public void actionPerformed(ActionEvent evt) {
					manager = "Staff";
					System.out.println("Staff Manager");
					getEmployeeJList();
					JFrame manageStaff = getManageStaffJFrame();
					manageStaff.pack();
					manageStaff.setLocationRelativeTo(null);
					manageStaff.setVisible(true);
					adminJFrame.dispose();
				}
			};
		}
		return manageStaffAction;
	}
	
	private AbstractAction getAddStaffAction() {
		if(addStaffAction == null) {
			addStaffAction = new AbstractAction("Add", null) {
				public void actionPerformed(ActionEvent evt) {
					if (manager.equals("Course")) {
						System.out.println("Not Implemented");
					}
					else {
						addStaffJPanel = getAddStaffJPanel();
						addStaffJPanel.pack();
						addStaffJPanel.setLocationRelativeTo(null);
						addStaffJPanel.setVisible(true);
					}
				}
			};
		}
		return addStaffAction;
	}
	
	private AbstractAction getRemoveStaffAction() {
		if(removeStaffAction == null) {
			removeStaffAction = new AbstractAction("Remove", null) {
				public void actionPerformed(ActionEvent evt) {
					if (manager.equals("Student")) {
						String uvid = employeeJList.getSelectedValue().toString();
						uvid = uvid.substring(0, uvid.indexOf(":"));
						System.out.println("Removing " + uvid);
						uSys.removeStudent(uvid);
						employeeJListModel.removeElementAt(employeeJList.getSelectedIndex());
					}
					else if (manager.equals("Course")) {
						String csid = employeeJList.getSelectedValue().toString();
						csid = csid.substring(0, csid.indexOf(":"));
						currentCourseInView = csid;
						System.out.println("Removing " + csid);
						uSys.removeCourseSection(csid);
						employeeJListModel.removeElementAt(employeeJList.getSelectedIndex());
					}
					else {
						String sid = employeeJList.getSelectedValue().toString();
						sid = sid.substring(0, sid.indexOf(":"));
						System.out.println("Removing " + sid);
						uSys.removeEmployee(sid);
						employeeJListModel.removeElementAt(employeeJList.getSelectedIndex());
					}
				}
			};
		}
		return removeStaffAction;
	}
	
	private JFrame getAddStaffJPanel() {
		if(addStaffJPanel == null) {
			addStaffJPanel = new JFrame();
			GroupLayout addStaffJPanelLayout = new GroupLayout((JComponent)addStaffJPanel.getContentPane());
			addStaffJPanel.getContentPane().setLayout(addStaffJPanelLayout);
			addStaffJPanel.setTitle("Add Employee");
			addStaffJPanel.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			addStaffJPanelLayout.setHorizontalGroup(addStaffJPanelLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(addStaffJPanelLayout.createParallelGroup()
				    .addComponent(getAddStaffFNameLabel(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffLNameLabel(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffDOBLabel(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffSexLabel(), GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(addStaffJPanelLayout.createParallelGroup()
				    .addGroup(addStaffJPanelLayout.createSequentialGroup()
				        .addComponent(getAddStaffFNameText(), GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(addStaffJPanelLayout.createSequentialGroup()
				        .addComponent(getAddStaffLNameText(), GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(addStaffJPanelLayout.createSequentialGroup()
				        .addComponent(getAddStaffDOBText(), GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(addStaffJPanelLayout.createSequentialGroup()
				        .addComponent(getAddStaffSexText(), GroupLayout.PREFERRED_SIZE, 175, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE))
				    .addGroup(GroupLayout.Alignment.LEADING, addStaffJPanelLayout.createSequentialGroup()
				        .addPreferredGap(getAddStaffFNameText(), getAddStaffButton(), LayoutStyle.ComponentPlacement.INDENT)
				        .addComponent(getAddStaffButton(), GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 96, Short.MAX_VALUE)))
				.addContainerGap(27, 27));
			addStaffJPanelLayout.setVerticalGroup(addStaffJPanelLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(addStaffJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getAddStaffFNameLabel(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffFNameText(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(addStaffJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getAddStaffLNameLabel(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffLNameText(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(addStaffJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getAddStaffDOBLabel(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffDOBText(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(addStaffJPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
				    .addComponent(getAddStaffSexLabel(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				    .addComponent(getAddStaffSexText(), GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
				.addGap(16)
				.addComponent(getAddStaffButton(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(94, Short.MAX_VALUE));
		}
		return addStaffJPanel;
	}
	
	private JLabel getAddStaffFNameLabel() {
		if(addStaffFNameLabel == null) {
			addStaffFNameLabel = new JLabel();
			addStaffFNameLabel.setText("First Name: ");
		}
		return addStaffFNameLabel;
	}
	
	private JLabel getAddStaffLNameLabel() {
		if(addStaffLNameLabel == null) {
			addStaffLNameLabel = new JLabel();
			addStaffLNameLabel.setText("Last Name:");
		}
		return addStaffLNameLabel;
	}
	
	private JLabel getAddStaffDOBLabel() {
		if(addStaffDOBLabel == null) {
			addStaffDOBLabel = new JLabel();
			addStaffDOBLabel.setText("DOB:");
		}
		return addStaffDOBLabel;
	}
	
	private JLabel getAddStaffSexLabel() {
		if(addStaffSexLabel == null) {
			addStaffSexLabel = new JLabel();
			addStaffSexLabel.setText("Sex:");
		}
		return addStaffSexLabel;
	}
	
	private JTextField getAddStaffFNameText() {
		if(addStaffFNameText == null) {
			addStaffFNameText = new JTextField();
		}
		return addStaffFNameText;
	}
	
	private JTextField getAddStaffLNameText() {
		if(addStaffLNameText == null) {
			addStaffLNameText = new JTextField();
		}
		return addStaffLNameText;
	}
	
	private JTextField getAddStaffDOBText() {
		if(addStaffDOBText == null) {
			addStaffDOBText = new JTextField();
		}
		return addStaffDOBText;
	}
	
	private JTextField getAddStaffSexText() {
		if(addStaffSexText == null) {
			addStaffSexText = new JTextField();
		}
		return addStaffSexText;
	}
	
	private JButton getAddStaffButton() {
		if(addStaffButton == null) {
			addStaffButton = new JButton();
			addStaffButton.setText("Add");
			addStaffButton.setAction(getAddStaffAndCloseAction());
		}
		return addStaffButton;
	}
	
	private AbstractAction getAddStaffAndCloseAction() {
		if(addStaffAndCloseAction == null) {
			addStaffAndCloseAction = new AbstractAction("Add", null) {
				public void actionPerformed(ActionEvent evt) {
					if (manager.equals("Student")) {
						uSys.addStudent(addStaffLNameText.getText(), addStaffFNameText.getText(), 1986, 12, 25, "male");
					}
					else {
						uSys.addEmployee(addStaffLNameText.getText(), addStaffFNameText.getText(), 1986, 12, 25, "male");
					}
					addStaffLNameText.setText("");
					addStaffFNameText.setText("");
					addStaffDOBText.setText("");
					addStaffSexText.setText("");
					getEmployeeJList(); //refresh list
					addStaffJPanel.dispose();
				}
			};
		}
		return addStaffAndCloseAction;
	}
	
	private AbstractAction getManageStudentsAction() {
		if(manageStudentsAction == null) {
			manageStudentsAction = new AbstractAction("Manage Students", null) {
				public void actionPerformed(ActionEvent evt) {
					manager = "Student";
					getEmployeeJList();
					System.out.println("Student Manager");
					JFrame manageStaff = getManageStaffJFrame();
					manageStaff.pack();
					manageStaff.setLocationRelativeTo(null);
					manageStaff.setVisible(true);
					adminJFrame.dispose();
				}
			};
		}
		return manageStudentsAction;
	}
	
	private AbstractAction getManageCoursesAction() {
		if(manageCoursesAction == null) {
			manageCoursesAction = new AbstractAction("Manage Courses", null) {
				public void actionPerformed(ActionEvent evt) {
					manager = "Course";
					getEmployeeJList();
					System.out.println("Course Manager");
					JFrame manageStaff = getManageStaffJFrame();
					manageStaff.pack();
					manageStaff.setLocationRelativeTo(null);
					manageStaff.setVisible(true);
					adminJFrame.dispose();
				}
			};
		}
		return manageCoursesAction;
	}
	
	private JFrame getEmployeeStatsJFrame() {
		if(employeeStatsJFrame == null) {
			employeeStatsJFrame = new JFrame();}
		GroupLayout employeeStatsJFrameLayout = new GroupLayout((JComponent)employeeStatsJFrame.getContentPane());
			employeeStatsJFrame.getContentPane().setLayout(employeeStatsJFrameLayout);
			employeeStatsJFrameLayout.setVerticalGroup(employeeStatsJFrameLayout.createSequentialGroup()
				.addContainerGap(17, 17)
				.addComponent(getJScrollPane1(), GroupLayout.PREFERRED_SIZE, 165, GroupLayout.PREFERRED_SIZE)
				.addGap(59)
				.addGroup(employeeStatsJFrameLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, employeeStatsJFrameLayout.createSequentialGroup()
				        .addComponent(getAddCourseToEmployee(), GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 53, Short.MAX_VALUE))
				    .addGroup(employeeStatsJFrameLayout.createSequentialGroup()
				        .addComponent(getJScrollPane2(), GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
				        .addGap(0, 0, Short.MAX_VALUE)))
				.addContainerGap(81, 81));
			employeeStatsJFrameLayout.setHorizontalGroup(employeeStatsJFrameLayout.createSequentialGroup()
				.addContainerGap()
				.addGroup(employeeStatsJFrameLayout.createParallelGroup()
				    .addGroup(GroupLayout.Alignment.LEADING, employeeStatsJFrameLayout.createSequentialGroup()
				        .addComponent(getAddCourseToEmployee(), GroupLayout.PREFERRED_SIZE, 107, GroupLayout.PREFERRED_SIZE)
				        .addGap(27)
				        .addComponent(getJScrollPane2(), GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE))
				    .addGroup(employeeStatsJFrameLayout.createSequentialGroup()
				        .addComponent(getJScrollPane1(), GroupLayout.PREFERRED_SIZE, 301, GroupLayout.PREFERRED_SIZE)))
				.addContainerGap(12, Short.MAX_VALUE));
			employeeStatsJFrame.setTitle("Employee Info");
			employeeStatsJFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		//}
		return employeeStatsJFrame;
	}
	
	private JTextArea getEmployeeInfoText() {
		if(employeeInfoText == null) {
			employeeInfoText = new JTextArea();
		}
			String emp = employeeJList.getSelectedValue().toString();
			System.out.println("Selected value: " + emp);
			String sid = emp.substring(0, emp.indexOf(":"));
			String display = "";
			currentEmpInView = sid;
			try {
				display = uSys.getEmployee(sid).toString();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			employeeInfoText.setText(display);
			employeeInfoText.setEditable(false);
			employeeInfoText.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
		//}
		return employeeInfoText;
	}
	
	private AbstractAction getViewInfoAction() {
		if(viewInfoAction == null) {
			viewInfoAction = new AbstractAction("View", null) {
				public void actionPerformed(ActionEvent evt) {
					employeeStatsJFrame = getEmployeeStatsJFrame();
					employeeStatsJFrame.pack();
					employeeStatsJFrame.setLocationRelativeTo(null);
					employeeStatsJFrame.setVisible(true);
				}
			};
		}
		return viewInfoAction;
	}
	
	private JScrollPane getJScrollPane1() {
		if(jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getEmployeeInfoText());
		}
		return jScrollPane1;
	}
	
	private JButton getAddCourseToEmployee() {
		if(addCourseToEmployee == null) {
			addCourseToEmployee = new JButton();
			addCourseToEmployee.setText("Add Course");
			addCourseToEmployee.setAction(getAddCourseToEmployeeButton());
		}
		return addCourseToEmployee;
	}

	
	private JScrollPane getJScrollPane2() {
		if(jScrollPane2 == null) {
			jScrollPane2 = new JScrollPane();
			manager = "Course";
			jScrollPane2.setViewportView(getEmployeeJList());
		}
		return jScrollPane2;
	}
	
	private AbstractAction getAddCourseToEmployeeButton() {
		if(addCourseToEmployeeButton == null) {
			addCourseToEmployeeButton = new AbstractAction("Add Course", null) {
				public void actionPerformed(ActionEvent evt) {
					String csid = employeeJList.getSelectedValue().toString();
					csid = csid.substring(0, csid.indexOf(":"));
					System.out.println("Add "+ csid + " to " + currentEmpInView);
					uSys.assignProfessorToCourse(currentEmpInView, csid);
					jScrollPane1 = getJScrollPane1();
					jScrollPane1.repaint();
				}
			};
		}
		return addCourseToEmployeeButton;
	}

}
